using UnityEngine;
using System.Collections;

public class scoreAjoutScript : MonoBehaviour
{

    private GameObject ship;
    public int attractNumber;
    public int attractNumberprevious;
    bool nbr;

    void Start()
    {
        attractNumber = 0;
        attractNumberprevious = 0;
        ship = GameObject.Find("ship");
        guiText.enabled = false;
        nbr = false;
    }


    void Update()
    {
        guiText.enabled = false;
        attractNumberprevious = attractNumber;
        shipControllerScript shipScript = ship.GetComponent<shipControllerScript>();
        attractNumber = shipScript.attractNumber * 100;
        if (attractNumberprevious != attractNumber)
            nbr = false;

        if (!nbr)
            if (attractNumber != attractNumberprevious || attractNumber != 0)
            {
                if(attractNumber == 100)
                   StartCoroutine(display(Color.green));
                else if(attractNumber == 200)
                    StartCoroutine(display(Color.yellow));
                else
                    StartCoroutine(display(Color.red));
                
            }
    }

    IEnumerator display(Color c)
    {

        string format = System.String.Format("+ {0}", attractNumber);
        guiText.text = format;
        guiText.material.color = c;
        guiText.enabled = true;
        yield return new WaitForSeconds(0.6f);
        guiText.enabled = false;
        nbr = true;
    }


}